package com.baosight.sczx.zm.ca.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.Utils;
import com.baosight.sczx.zm.ca.domain.VZMCA14;

public class ServiceZMCA25 extends ServiceEPBase{
	/**
	 * 页面初始化，返回组织好的层级小代码
	 * 
	 * @param EiInfo
	 * @return EiInfo
	 */
	public EiInfo initLoad(EiInfo inInfo) {
		
		inInfo.addBlock(this.getType());
		inInfo.addBlock(this.getMaterialType(dao));
		
		return inInfo;//return this.query(inInfo);
	}

	
	public EiInfo queryByRate(EiInfo inInfo) {
		VZMCA14 daoBean = new VZMCA14();
		inInfo.addBlock(Utils.generateOutBlock("departmentPlan", daoBean, inInfo, "ZMCA14.queryRateByDepartmentPlan", false));
		inInfo.addBlock(Utils.generateOutBlock("departmentActual", daoBean, inInfo, "ZMCA14.queryRateByDepartmentActual", false));

		return inInfo;
	}
	
	
	public EiInfo queryByAmount(EiInfo inInfo) {
		VZMCA14 daoBean = new VZMCA14();
		inInfo.addBlock(Utils.generateOutBlock("departmentPlan", daoBean, inInfo, "ZMCA14.queryAmountByDepartmentPlan", false));
		inInfo.addBlock(Utils.generateOutBlock("departmentActual", daoBean, inInfo, "ZMCA14.queryAmountByDepartmentActual", false));

		return inInfo;
	}

	
	private EiBlock getType(){
		EiBlock block = new EiBlock("cmes.ca.type");
		
		EiColumn eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);		
		
		eiColumn = new EiColumn("display");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		Map<String,String> map = new HashMap<String,String>();
		map.put("value", "0");
		map.put("display", "材料超节率");
		block.addRow(map);
		
		map = new HashMap<String,String>();
		map.put("value", "1");
		map.put("display", "材料消耗量");
		block.addRow(map);
			
		return block;		
	}	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private EiBlock getMaterialType(Dao _dao)
	{
		EiBlock block = new EiBlock("cmes.ca.materialtype");
		
		EiColumn eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);		
		
		eiColumn = new EiColumn("display");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
//		Map<String,String> map = new HashMap<String,String>();
//		map.put("value", "");
//		map.put("display", "");
//		block.addRow(map);
		
		List<Map> list = _dao.query("ZMCA14.queryMaterialType", null);
		
		block.addRows(list);
		return block;					
	}
	
	
	
	
}
